<?php

namespace app\api\controller;

use app\model\Article as ArticleModel;
use think\Db;

/**
 * @title    首页接口
 * @desc    首页接口
 * Class Index
 * @package app\api\controller
 */

class Index extends Common
{

    /**
     * @title 查询结果
     * @desc  查询结果
     *
     *
     * @return Array $list 文章列表
     */
    public function search()
    {
        $title = $this->request->param('title');
        $limit = $this->request->param('limit');
        if ($title != '') {
            $map[] = ['title', 'like', '%' . $title . '%'];
        }
        if (!$limit) {
            $limit = 10;
        }
        $list = ArticleModel::where($map)
        // ->where('cname', $cname)
            ->field(['id', 'cname', 'title', 'create_time'])
            ->order('id desc')
            ->paginate($limit);
        return $this->jsonPage($list->total(), $list->toArray()['data']);
    }}
